<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>登录</title>

    <link rel="shortcut icon" href="${ctxPath}/static/favicon.ico">
    <link href="${ctxPath}/static/libs/bootstrap/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxPath}/static/libs/font-awesome/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxPath}/static/libs/hisui/css/hisui.min.css" rel="stylesheet">
    <link href="${ctxPath}/static/backend/common.css" rel="stylesheet">
    <link href="${ctxPath}/static/backend/login.css" rel="stylesheet">
    <script>
	    if (window.top !== window.self) {
	        window.top.location = window.location;
	    }
    </script>
    <script src="${ctxPath}/static/libs/jquery/jquery.min.js?v=2.1.4"></script>
    <script src="${ctxPath}/static/libs/bootstrap/bootstrap.min.js?v=3.3.6"></script>
    <script src="${ctxPath}/static/libs/hisui/js/jquery.hisui.min.js"></script>
    <script src="${ctxPath}/static/libs/layer/layer.js"></script>
    <script src="${ctxPath}/static/libs/jquery-form/jquery.form.js"></script>
    <script src="${ctxPath}/static/common/js/Sys.js"></script>
    <script src="${ctxPath}/static/backend/rsa.encrypt.js"></script>
    <script src="${ctxPath}/static/libs/qrcode/qrcode.min.js"></script>
    <script type="text/javascript">
        Sys.init("${ctxPath}", "${backendPath}", "${frontPath}");
        var uuid = "";
        var pollingNum = 0;
        var polling;
        $(document).ready(function () {
        	$('#codeLogin').click(function () {
        		clearInterval(polling);//切换为用户名密码登录时，清除轮询任务
        		pollingNum = 0;
        		$("#codeLogin").addClass("selected");
        		$("#scanLogin").removeClass("selected");
        		$("#userCode").css("display","");
        		$("#qrScan").css("display","none");
        		$("#qrScan").html("");
            });
        	$('#scanLogin').click(function () {
        		clearInterval(polling);
        		pollingNum = 0;
        		$("#scanLogin").addClass("selected");
        		$("#codeLogin").removeClass("selected");
        		$("#userCode").css("display","none");
        		$("#qrScan").css("display","");
        		$("#qrScan").html("");
	    		Sys.ajax(Sys.backendPath + "/scanLogin",{},function (data) {
	    			uuid = data.split("=")[1];
	    			var obj = document.getElementById("qrScan");
	        	    new QRCode(obj,{
	        	        text:data,
	        	        width:'200',
	        	        height:'200'
	        	    });
   	            }, function (data) {
   	            },"json",true,"获取中...");
	    		polling = setInterval("isLogin()", 1000);
            });
            $('#kaptcha').click(function () {
                var url = "${ctxPath}/kaptcha?s=" + Math.random();
                $("#kaptcha").attr("src", url);
            });
            $("#btnReset").click(function () {
                $("input[name='username']").val('');
                $("input[name='password']").val('');
            });
            $("#btnOK").click(function () {
				var encrypt = new JSEncrypt();
				encrypt.setPublicKey();
                var password = encrypt.encrypt($('#password').val());
                $('#password').val(encodeURIComponent(password));
                Sys.ajaxForm("loginForm", function (res) {
                    location.href = location.protocol + "//" + location.host + "${backendPath}";
                }, function (res) {
                    if (res.status == 200) {
                        location.href = location.protocol + "//" + location.host + "${backendPath}";
                    } else {
                        Sys.error(res.responseJSON.message);
                        $('#kaptcha').trigger("click");//自动刷新验证码
                        $("#tips").removeClass("hidden");
                        $("#tips").html("<i class='fa fa-minus-circle'></i>" + res.responseJSON.message)
                    }
                }, null, null, "登录中...");

                return false;
            });
            $(window).resize(function () {
                /* 轮播图片高度 DY */
                var car_height = $(".login_contain").height();
                $(".login_carousel div").css("height", car_height + 'px');
                /* 页眉padding-top高度 DY */
                var car_height = $(".login_header").height();
                $(".login_xietong").css("padding-top", (car_height / 2 - 20) + 'px');
                $(".login_welcome").css("padding-top", (car_height / 2 - 14) + 'px');
                $(".login_dhc").css("padding-top", (car_height / 2 - 29.5) + 'px');
                /*页脚margin-top高度 DY */
                var car_height = $(".index").height();
                $(".login_footer").css("margin-top", (car_height * 0.17) + 'px');
            })
            $(window).resize();
        });

        //忘记密码
        function forgotPass() {
            Sys.open("密码重置", Sys.backendPath + "/passwordReset", ["450px", "550px"], function (layero, index, iframeWin) {
                Sys.layer.iframeAuto(index);
            }, false);
        }

        //微信登录
        function wechatLogin() {
            Sys.open("微信登录", Sys.backendPath + "/wechatLogin", ["450px", "400px"], function (layero, index, iframeWin) {
                Sys.layer.iframeAuto(index);
            }, false);
        }

        //手机扫码登录       
        function isLogin() {
            pollingNum++;
            $.ajax({
                type: "POST",
                url: Sys.backendPath + "/isLogin",
                data: {uuid: uuid},
                dataType: "json",
                async: true,
                error: function (res) {
                    Sys.error(res.responseJSON.message);
                },
                success: function (res) {
                    if (res.data.isScan == "scan") {
                        if ($("#qrScan")[0].childNodes[0].tagName != "IMG") {
                            var userAvatar = res.data.avatar;
                            var userName = res.data.userName;
                            var content = '';
                            if (userAvatar != null && userAvatar != undefined && userAvatar != "" && userAvatar != "null") {
                                content += '<img src="' + Sys.backendPath + '/file/image/' + userAvatar + '" style="width:80px;height:80px">';
                            } else {
                                content += '<img src="' + Sys.backendPath + '/static/common/img/default.png' + '" style="width:80px;height:80px">';
                            }
                            content += '<div style="margin-top:5px">' + userName + '</div>'
                            content += '<div style="margin:15px 0px 20px 0px">请在手机上确认登录</div>'
                            content += '<a href="javascript:backScan()" style="color:#4B92DB">返回手机扫码登录</a>'
                            $("#qrScan").html(content)
                        }
                    } else if (res.data.isScan == "login") {
                        clearInterval(polling);
                        location.href = location.protocol + "//" + location.host + "${backendPath}";
                    }
                }
            })
            if (pollingNum == 300) {//五分钟后刷新二维码
                $('#scanLogin').trigger("click");
            }
        }

        //返回扫码登录
        function backScan() {
            $('#scanLogin').trigger("click");//返回刷新二维码
        }
        
    </script>
</head>

<body>
	<div class="index">
	    <!--LOGO-->
	    <div class="login_header">
	        <div class="login_header_content">
	            <div class="login_title">${sysFullName!}</div>
	            <!-- <div class="login_title_sub">${sysFullName!}</div> -->
	        </div>
	    </div>
	    <!--LOGO-->
	    <div class="login_contain">
	        <div class="login_carousel"></div>
	    </div>
	    <!--登录框 SCQ-->
		@if(tool.getKaptchaOpen() == true){
			@if(scanLoginOpen){
    		<div class="loginbox_cq" style="height: 400px;margin-top: -200px;">
        	@}else{
    		<div class="loginbox_cq" style="height: 340px;margin-top: -200px;">
        	@}
        @}else{
        	@if(scanLoginOpen){
    		<div class="loginbox_cq" style="height: 340px;margin-top: -200px;">
        	@}else{
    		<div class="loginbox_cq">
        	@}
        @}
			<form id="loginForm" name="loginForm" action="${backendPath}/callback?client_name=form" method="post">
				<div class="tcq">欢迎登录</div>
				<!--  如果配置了显示扫码登录则显示 -->
				@if(scanLoginOpen){
				<ul class="nav nav-justified" style="margin-top: -10px">
				  	<li id="codeLogin" class="selected">用户名密码登录</li>
				  	<li id="scanLogin">手机扫码登录</li>
		  		</ul>
                @}
				@if(tips != ''){
					<div class="alert alert-danger" role="alert" id="tips">${tips!}</div>
				@}else{
					<div class="alert alert-danger hidden" role="alert" id="tips"></div>
				@}
				<div id="userCode">
	                <div class="form-group">
	                    <div class="input-group">
	                        <div class="input-group-addon"><i class="fa fa-user"></i></div>
	                        <input type="text" id="username" name="username" class="form-control" placeholder="请输入用户名...">
	                    </div>
	                </div>
	                <div class="form-group">
	                    <div class="input-group">
	                        <div class="input-group-addon"><i class="fa fa-lock"></i></div>
	                        <input type="password" id="password" name="password" class="form-control" autocomplete="off"
	                               placeholder="请输入密码...">
	                    </div>
	                </div>
	                @if(tool.getKaptchaOpen() == true){
	                <div class="form-group">
	                    <div class="input-group">
	                        <input class="form-control" type="text" id="kaptcha_input" name="kaptcha" placeholder="验证码"
	                               required="">
	                        <div class="input-group-addon" title="点击更换验证码">
	                            <img src="${ctxPath}/kaptcha" id="kaptcha"/>
	                        </div>
	                    </div>
	                </div>
	                @}
	                @if(isShow){
	                <div class="checkbox" style="text-align: left">
	                    <label>
	                        <!-- <input type="checkbox" name="remember" value="true">记住我 -->
	                    </label>
	                </div>
	                @}
                	<!-- <button type="button" class="btn btn-warning " id="btnReset">重置</button> -->
                	<div class="form-group">
                		<button type="submit" class="btn btn-primary btn-lg btn-block" id="btnOK">登录</button>
                    </div>
                	<div style="text-align: left;padding-top: 45px;font-size: 12px;">
                    	@if(showResetPass){
                    	<a href="javascript:forgotPass()">忘记密码？</a>
                    	@}
                    	@if(wxLoginOpen){
                    	<a href="javascript:wechatLogin()">微信登录</a>
                    	@}
                	</div>
        		</div>
        		@if(tool.getKaptchaOpen() == true){
        			<div align="center" id="qrScan" style="display:none;margin-top:30px">
		        @}else{
		        	<div align="center" id="qrScan" style="display:none;margin-top:15px">
		        @}

	        	</div>
        	</form>

		</div>
	    <!--登录框 ECQ-->
	    <!--页脚-->
        <div class="login_footer">
            <div class="log_f">
            	<div class="login_logo"><img style="width:89px;height:20px;" src="/static/common/img/btlogo.png" /><!-- <i class="fa fa-registered"></i> --></div>
                <!-- <div class="login_logo"><img src="/static/common/img/logo2.png" /></div> -->
                <i class="fa fa-copyright"></i>
                <span id="loginCopy"></span>
                <span>东华医为科技有限公司版权所有</span>
                <!-- <span>${sysFullName!}</span>   -->

            </div>
        </div>
        <!--页脚-->
    </div>
</body>
<style>
	.selected{
		padding-bottom:5px;
		border-bottom: solid 0.1px #4B92DB;
	    color: #4B92DB;
	}
    li {
        cursor: pointer;
    }
    li:hover {
        background-color: #F5F5F5;
    }
</style>
<script>
	//监听用户名回车事件
	$('#username').bind('keypress', function(event) {
		if (event.keyCode == "13") {
			event.preventDefault();
			if($("#username").val()==""){
				return false;
			}else{
				$("#password").focus();
			}
		}
	});
</script>
</html>
